/**
 * this class to find destination file in the disc
 */
package cn.netjava.softkid.chapter07;

import java.io.File;

/**
 * @author softkid
 * 
 */
public class CountFileLength {
	
	/**
	 * count the of file under a directory
	 *	@param: directory name
	 */ 
	public long countLength(String name)
	{
		File f = new File(name);
		
		long len=0;
		File[] files = f.listFiles();
	
		if(files!=null)
		{
			for(int i=0;i<files.length;i++)
			{
				File temp = files[i];
				if(temp.isFile())
				{
					len+=temp.length();
				}
				else if(temp.isDirectory())
				{
					len+=countLength(temp.getAbsolutePath());
					
				}
				else
				{
					System.out.println(temp.getName());
					System.out.println(temp.getAbsolutePath());
				}
			}
		}
		return len;
	
	}
	public static void main(String args[]) 
	{
//		long totalLen=0;
//		File[] roots = File.listRoots();
//		for(int i=0;i<roots.length;i++)
//		{
//			String name = String.valueOf(roots[i]);
//			CountFileLength df = new CountFileLength();
//			long len = df.countLength(name);
//			System.out.println(name+":"+len);
//			totalLen+=len;
//		}
//		System.out.println(totalLen);
		CountFileLength df = new CountFileLength();
		long len = df.countLength("D:\\songs");
		System.out.println(len);
	}
	
}
